#include <gtest/gtest.h>

#include <vector>

#include "algorithm/common/include/bitDiffNums.h"
#include "algorithm/common/include/mtBasic.h"
#include "algorithm/common/include/utils.h"
using namespace std;
TEST(TestMaxDip, MeiTuanSuits) {
    std::vector<int> nums = {5, 6};
    EXPECT_TRUE(getDis(nums, 1));
}
TEST(TestFlipChess, MeiTuanSuits) {
    vector<vector<int>> A = {
        {0, 0, 1, 1}, {1, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}};
    const int rows = A.size();
    const int cols = A[0].size();
    vector<vector<int>> f = {{2, 2}, {3, 3}, {4, 4}};
    vector<vector<int>> result = {
        {0, 1, 1, 1}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}};
    auto res = flipChess(A, f);
    const int N = rows * cols;
    EXPECT_TRUE(valuesIsSame(result, res, 0));
    A = {{0, 1, 0, 0}, {1, 0, 1, 0}, {1, 1, 0, 0}, {1, 0, 0, 1}};
    f = {{4, 2}};
    res = flipChess(A, f);
    result = {{0, 1, 0, 0}, {1, 0, 1, 0}, {1, 0, 0, 0}, {0, 0, 1, 1}};
    EXPECT_TRUE(valuesIsSame(result, res, 0));
}

TEST(TestNumsOfOnes, MeiTuanSuits) {
    EXPECT_EQ(onesOfNum(5), 2);
    EXPECT_EQ(bitDiffNums(15, 8), 3);
}

TEST(TestArrayPrint, MeiTuanSuits) {
    std::vector<std::vector<int>> arr = {
        {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
    const int N = 4;
    std::vector<int> truth = {4,  3,  8, 2,  7,  12, 1,  6,
                              11, 16, 5, 10, 15, 9,  14, 13};
    auto res = arrayPrint(arr, N);
    EXPECT_TRUE(valuesIsSame(res, truth));
}

TEST(TestMaxProfit, MeiTuanSuits) {
    vector<int> nums = {10, 22, 5, 75, 65, 80};
    EXPECT_EQ(maxProfitMt(nums, 6), 87);
}

TEST(TestCountPath, MeiTuanSuits) {
    vector<vector<int>> nums = {
        {2, 0, 0, 0}, {0, -1, -1, 0}, {0, -1, 1, 0}, {0, 0, 0, 0}};
    int m = 4, n = 4;

    EXPECT_EQ(countPath(nums, n, m), 2);
    nums = {{0, 1, 0}, {2, 0, 0}};
    n = 2;
    m = 3;
    EXPECT_EQ(countPath(nums, n, m), 2);
}

TEST(TestLargestArea, MeiTuanSuits) {
    vector<int> nums = {3, 4, 7, 8, 1, 2};
    EXPECT_EQ(largestRectangleArea(nums), 14);
    nums = {2, 1, 5, 6, 2, 3};
    EXPECT_EQ(largestRectangleArea(nums), 10);
    nums = {2, 1, 1};
    EXPECT_EQ(largestRectangleArea(nums), 3);
    nums = {2, 1, 5, 6, 2, 4};
    EXPECT_EQ(largestRectangleArea(nums), 10);
}

TEST(TestMaximalRectangle, MeiTuanSuits) {
    vector<vector<char>> nums = {{'1', '0', '1', '0', '0'},
                                 {'1', '0', '1', '1', '1'},
                                 {'1', '1', '1', '1', '1'},
                                 {'1', '0', '0', '1', '0'}};

    EXPECT_EQ(maximalRectangle(nums), 6);
    nums = {{'0', '1'}, {'1', '0'}};
    EXPECT_EQ(maximalRectangle(nums), 1);
}
